package org.javaqq.face.main.tree;

import java.text.Collator;   
import java.text.RuleBasedCollator;   
import java.util.Comparator;   
import java.util.Locale;   
  
public class ChinaWordCompartor implements Comparator {   
	
		private static ChinaWordCompartor compartor;
	
        public static ChinaWordCompartor getInstance(){
        	if(compartor==null){
        		compartor=new ChinaWordCompartor();
        	}
        	return compartor;
        }
        RuleBasedCollator collator;   
           
        public ChinaWordCompartor(){   
            collator = (RuleBasedCollator) Collator.getInstance(Locale.CHINA);   
        }   
        public int compare(Object p1, Object p2) {   
              String name1="";
              String name2="";
              if(p1 instanceof ContactNode){
            	  ContactNode contact=(ContactNode) p1;
            	  name1=contact.getContact().getNickName();
              }
              if(p1 instanceof GroupNode){
            	  GroupNode group=(GroupNode) p1;
            	  name1 = group.getGroup().getGroupName();
              }
              
              if(p2 instanceof ContactNode){
            	  ContactNode contact=(ContactNode) p2;
            	  name2=contact.getContact().getNickName();
              }
              if(p2 instanceof GroupNode){
            	  GroupNode group=(GroupNode) p2;
            	  name2 = group.getGroup().getGroupName();
              }
              
            return collator.compare(name1,name2)<0 ? -1 : 1;   	
        }   
           
    }  
